<?php
	
class M_for_enrollment_id Extends MY_Model{
	
		protected $_table = 'for_enrollment_id';

		public function __construct()
		{
			parent::__construct();
		}
		
		public function get_enrollment_id()
		{
			$sql = "SELECT for_e_id
					FROM for_enrollment_id 
					LIMIT 1";
			$query = $this->db->query($sql);
			return $query->num_rows() >=1 ? $query->row() : FALSE;
		}
		
		public function update_enrollment_id($data)
		{
			$this->db->truncate('for_enrollment_id');
			
			$this->db->insert('for_enrollment_id', $data); 
			
			return $this->db->affected_rows() >=1 ? TRUE : FALSE;
		}

		public function get_assessment_fee($e_id)
		{
			$e_id = intval($e_id);
			
			$sql = "SELECT remarks,
						   ammt_paid
					FROM assessment_fees 
					WHERE enrollment_id = ? 
					LIMIT 1";
			$query = $this->db->query($sql,array($e_id));
			return $query->num_rows() >=1 ? TRUE : FALSE;
		}
		
		public function print_assessment_fee($e_id)
		{
			$e_id = intval($e_id);
			
			$sql = "SELECT assessment_fees.remarks,
						   assessment_fees.ammt_paid,
						   enrollments.age,
						   enrollments.schedule_for_testing,
						   enrollments.hear_from
					FROM assessment_fees
					LEFT JOIN enrollments ON assessment_fees.enrollment_id = enrollments.e_id					
					WHERE assessment_fees.enrollment_id = ? 
					LIMIT 1";
			$query = $this->db->query($sql,array($e_id));
			return $query->num_rows() >=1 ? $query->row() : FALSE;
		}

		public function get_for_e_id()
		{
			$sql = "SELECT for_e_id
					FROM for_enrollment_id 
					LIMIT 1";
			$query = $this->db->query($sql);
			if( $query->num_rows() >=1 ){
				$r = $query->row();
				$v = $r->for_e_id;
				$tempv = $v+1;
					$data['for_e_id'] = $tempv;
					$this->db->truncate('for_enrollment_id');
					$this->db->insert('for_enrollment_id', $data);

				return $v;

			}else{
				return FALSE;
			}
		}

		public function get_student_number($id)
		{
			$sql = "SELECT e_id
							FROM enrollments
							WHERE e_student_id = ?";
			$query = $this->db->query($sql,array($id));
			return $query->num_rows() >=1 ? TRUE : FALSE;
		}

		public function check_id_generation($id)
		{
			$sql = "SELECT id_generated
							FROM enrollments
							WHERE e_id = ?";
			$query = $this->db->query($sql,array($id));
			$r = $query->row()->id_generated;
			if(intval($r) == 1){
				return TRUE;
			}else{
				return FALSE;
			}
		}
}